<?php
ini_set('display_errors', 1);
class newsAction extends sfActions
{
	public function execute()
	{

		$c = new Criteria();
		$this->processSort();
		$this->addSortCriteria($c);
		$news_list = IdolNewsPeer::doSelect($c);
		foreach ($news_list as $list) {
			$list_res[] = $list->toArray();
		}
		$this->news_item = $list_res;
	}
	public function sort()
	{
		//if($this->getRequestParameter('sort') && )

	}
	protected function addSortCriteria($c) {
		if ($sort_column = $this->getUser()->getAttribute('sort', null, 'sf_admin/idol/news/sort')) {
			$sort_column = IdolNewsPeer::translateFieldName($sort_column, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_COLNAME);
			if ($this->getUser()->getAttribute('type', null, 'sf_admin/idol/news/sort') == 'asc') {
				$c->addAscendingOrderByColumn($sort_column);
			} else {
				$c->addDescendingOrderByColumn($sort_column);
			}
		}
	}
	protected function processSort() {
		if ($this->getRequestParameter('sort')) {
			$this->getUser()->setAttribute('sort', $this->getRequestParameter('sort'), 'sf_admin/idol/news/sort');
			$this->getUser()->setAttribute('type', $this->getRequestParameter('type', 'asc'), 'sf_admin/idol/news/sort');
		}

		if (!$this->getUser()->getAttribute('sort', null, 'sf_admin/idol/news/sort')) {

		}
	}

}
?>